﻿using System.Linq;

using Cookbook.Services.Core.Domain;
using Cookbook.Services.Core.Persistency.NHibernate;
using Cookbook.Services.Core.Persistency.NHibernate.DataServices;

using NHibernate;
using NHibernate.Linq;

namespace Cookbook.Services.Host
{
    public class RestContext : NHibernateContext
    {
        private static readonly ISessionFactory sessionFactory;

        static RestContext()
        {
            sessionFactory = new NHibernateSessionFactoryManager().SessionFactory;
        }

        public IQueryable<Recipe> Recipes
        {
            get { return Session.Query<Recipe>(); }
        }

        public IQueryable<Product> Product
        {
            get { return Session.Query<Product>(); }
        }

        public IQueryable<Ingredient> Ingredients
        {
            get { return Session.Query<Ingredient>(); }
        }

        protected override ISession ProvideSession()
        {
            return sessionFactory.OpenSession();
        }
    }
}